<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>java8Stream详解 | 牛牛&amp;blog</title><meta name="author" content="牛牛"><meta name="copyright" content="牛牛"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="JDK8 Stream详解概念 Stream是Java8 API的新成员，它允许以声明性方式处理数据集合 。  特点 （1）代码简洁：函数式编程写出的代码简洁且意图明确，使用stream接口让你从此告别for循环。  （2）多核友好：Java函数式编程使得编写并行程序从未如此简单，你需要的全部就是调用一下方法。   流程1）第一步：把集合转换为流stream2）第二步：操作stream流strea">
<meta property="og:type" content="article">
<meta property="og:title" content="java8Stream详解">
<meta property="og:url" content="https://code-ran.gitee.io/2022/11/23/java8Stream%E8%AF%A6%E8%A7%A3/index.html">
<meta property="og:site_name" content="牛牛&amp;blog">
<meta property="og:description" content="JDK8 Stream详解概念 Stream是Java8 API的新成员，它允许以声明性方式处理数据集合 。  特点 （1）代码简洁：函数式编程写出的代码简洁且意图明确，使用stream接口让你从此告别for循环。  （2）多核友好：Java函数式编程使得编写并行程序从未如此简单，你需要的全部就是调用一下方法。   流程1）第一步：把集合转换为流stream2）第二步：操作stream流strea">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="">
<meta property="article:published_time" content="2022-11-23T07:28:14.000Z">
<meta property="article:modified_time" content="2023-11-02T03:32:07.129Z">
<meta property="article:author" content="牛牛">
<meta property="article:tag" content="java8">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content=""><link rel="shortcut icon" href="/img/myfavicon.png"><link rel="canonical" href="https://code-ran.gitee.io/2022/11/23/java8Stream%E8%AF%A6%E8%A7%A3/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'java8Stream详解',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-11-02 11:32:07'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/style.css"><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/ys.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">52</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">26</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">牛牛&amp;blog</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">java8Stream详解</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-11-23T07:28:14.000Z" title="发表于 2022-11-23 15:28:14">2022-11-23</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-11-02T03:32:07.129Z" title="更新于 2023-11-02 11:32:07">2023-11-02</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/java8%E7%9B%B8%E5%85%B3/">java8相关</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="java8Stream详解"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="JDK8-Stream详解"><a href="#JDK8-Stream详解" class="headerlink" title="JDK8 Stream详解"></a>JDK8 Stream详解</h1><h2 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h2><blockquote>
<p>Stream是Java8 API的新成员，它允许以声明性方式处理数据集合 。</p>
</blockquote>
<h2 id="特点"><a href="#特点" class="headerlink" title="特点"></a>特点</h2><blockquote>
<p>（1）<strong>代码简洁</strong>：函数式编程写出的代码简洁且意图明确，使用<em>stream</em>接口让你从此告别<em>for</em>循环。 </p>
<p>（2）<strong>多核友好</strong>：Java函数式编程使得编写并行程序从未如此简单，你需要的全部就是调用一下方法。 </p>
</blockquote>
<h2 id="流程"><a href="#流程" class="headerlink" title="流程"></a>流程</h2><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">1）第一步：把集合转换为流stream</span><br><span class="line">2）第二步：操作stream流</span><br><span class="line">stream流在管道中经过中间操作（intermediate operation）的处理，最后由最终操作(terminal operation)得到前面处理的结果</span><br></pre></td></tr></table></figure>

<h2 id="操作符"><a href="#操作符" class="headerlink" title="操作符"></a>操作符</h2><blockquote>
<p>两种：中间操作符、终止操作符</p>
</blockquote>
<h3 id="中间操作符"><a href="#中间操作符" class="headerlink" title="中间操作符"></a>中间操作符</h3><table>
<thead>
<tr>
<th>流方法</th>
<th>含义</th>
<th>示例</th>
</tr>
</thead>
<tbody><tr>
<td>filter</td>
<td>用于通过设置的条件过滤出元素</td>
<td>List<String> strings = Arrays.asList(“abc”, “”, “bc”, “efg”, “abcd”,””, “jkl”);List<String> filtered = strings.stream().filter(string -&gt; !string.isEmpty()).collect(Collectors.toList());</String></String></td>
</tr>
<tr>
<td>distinct</td>
<td>返回一个元素各异（根据流所生成元素的hashCode和equals方法实现）的流。</td>
<td>List<Integer> numbers = Arrays.asList(1, 2, 1, 3, 3, 2, 4);numbers.stream().filter(i -&gt; i % 2 == 0).distinct().forEach(System.out::println);</Integer></td>
</tr>
<tr>
<td>limit</td>
<td>会返回一个不超过给定长度的流。</td>
<td>List<String> strings = Arrays.asList(“abc”, “abc”, “bc”, “efg”, “abcd”,”jkl”, “jkl”);List<String> limited = strings.stream().limit(3).collect(Collectors.toList());</String></String></td>
</tr>
<tr>
<td>skip</td>
<td>返回一个扔掉了前n个元素的流。</td>
<td>List<String> strings = Arrays.asList(“abc”, “abc”, “bc”, “efg”, “abcd”,”jkl”, “jkl”);List<String> skiped = strings.stream().skip(3).collect(Collectors.toList());</String></String></td>
</tr>
<tr>
<td>map</td>
<td>接受一个函数作为参数。这个函数会被应用到每个元素上，并将其映射成一个新的元素（使用映射一词，是因为它和转换类似，但其中的细微差别在于它是“创建一个新版本”而不是去“修改”）。</td>
<td>List<String> strings = Arrays.asList(“abc”, “abc”, “bc”, “efg”, “abcd”,”jkl”, “jkl”);List<String> mapped = strings.stream().map(str-&gt;str+”-itcast”).collect(Collectors.toList());</String></String></td>
</tr>
<tr>
<td>flatMap</td>
<td>使用flatMap方法的效果是，各个数组并不是分别映射成一个流，而是映射成流的内容。所有使用map(Arrays::stream)时生成的单个流都被合并起来，即扁平化为一个流。</td>
<td>List<String> strings = Arrays.asList(“abc”, “abc”, “bc”, “efg”, “abcd”,”jkl”, “jkl”);Stream<Character> flatMap = strings.stream().flatMap(Java8StreamTest::getCharacterByString);</Character></String></td>
</tr>
<tr>
<td>sorted</td>
<td>返回排序后的流</td>
<td>List<String> strings1 = Arrays.asList(“abc”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);List<String> sorted1 = strings1.stream().sorted().collect(Collectors.toList());</String></String></td>
</tr>
</tbody></table>
<blockquote>
<p>示例代码：</p>
<p>1）filter</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述:根据条件过滤集合数据</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">filter</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;bc&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    List&lt;String&gt; filtered = strings.stream().filter(string -&gt; !string.isEmpty()).collect(Collectors.toList());</span><br><span class="line">    out.println(filtered);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>2）distinct</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述:去除集合中重复数据</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">distinct</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;bc&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    List&lt;String&gt; distincted = strings.stream().distinct().collect(Collectors.toList());</span><br><span class="line">    out.println(distincted);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>3）limit</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述:指定获取集合前x条数据，重新构造一个新的集合</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">limit</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;bc&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    List&lt;String&gt; limited = strings.stream().limit(<span class="number">3</span>).collect(Collectors.toList());</span><br><span class="line">    out.println(limited);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>4）skip</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述:排除集合前x条数据，把后面的数据重新构造一个新的集合</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">skip</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;bc&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    List&lt;String&gt; skiped = strings.stream().skip(<span class="number">3</span>).collect(Collectors.toList());</span><br><span class="line">    out.println(skiped);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>5）map</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述:对集合中所有元素统一处理</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">map</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;bc&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    List&lt;String&gt; mapped = strings.stream().map(str-&gt;str+<span class="string">&quot;-itcast&quot;</span>).collect(Collectors.toList());</span><br><span class="line">    out.println(mapped);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>6）flatMap</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述:对集合中所有元素统一处理</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">flatMap</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;bc&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    Stream&lt;String&gt; stringStream = strings.stream().map(x -&gt; x);</span><br><span class="line">    Stream&lt;String&gt; stringStream1 = strings.stream().flatMap(x -&gt; Arrays.asList(x.split(<span class="string">&quot; &quot;</span>)).stream());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>7）sorted</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 对集合进行排序</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">sorted</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings1 = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    List&lt;String&gt; strings2 = Arrays.asList(<span class="string">&quot;张三&quot;</span>, <span class="string">&quot;李四&quot;</span>, <span class="string">&quot;王五&quot;</span>, <span class="string">&quot;赵柳&quot;</span>, <span class="string">&quot;张哥&quot;</span>,<span class="string">&quot;李哥&quot;</span>, <span class="string">&quot;王哥&quot;</span>);</span><br><span class="line">    List&lt;Integer&gt; strings3 = Arrays.asList(<span class="number">10</span>, <span class="number">2</span>, <span class="number">30</span>, <span class="number">22</span>, <span class="number">1</span>,<span class="number">0</span>, -<span class="number">9</span>);</span><br><span class="line">    List&lt;String&gt; sorted1 = strings1.stream()</span><br><span class="line">                                    .sorted()</span><br><span class="line">                                    .collect(Collectors.toList());</span><br><span class="line">    List&lt;String&gt; sorted2 = strings2.stream()</span><br><span class="line">                                    .sorted(Collections.reverseOrder(Collator.getInstance(Locale.CHINA)))</span><br><span class="line">                                    .collect(Collectors.toList());</span><br><span class="line">    List&lt;Integer&gt; sorted3 = strings3.stream()</span><br><span class="line">                                    .sorted()</span><br><span class="line">                                    .collect(Collectors.toList());</span><br><span class="line">    System.out.println(sorted1);</span><br><span class="line">    System.out.println(sorted2);</span><br><span class="line">    System.out.println(sorted3);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p> Map、flatMap区别</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">map：对流中每一个元素进行处理</span><br><span class="line">flatMap：流扁平化，让你把一个流中的“每个值”都换成另一个流，然后把所有的流连接起来成为一个流 </span><br><span class="line">总结：map是对一级元素进行操作，flatmap是对二级元素操作。</span><br></pre></td></tr></table></figure>

<p><code>本质区别</code>：map返回一个值；flatmap返回一个流，多个值。</p>
<p><code>应用场景</code>：map对集合中每个元素加工,返回加工后结果；flatmap对集合中每个元素加工后，<br>做扁平化处理后（拆分层级，放到同一层）然后返回</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 方法一</span></span><br><span class="line"><span class="comment"> * 功能描述:  通过使用map、flatMap把字符串转换为字符输出对比区别</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">flatMap2Map</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abc&quot;</span>, <span class="string">&quot;bc&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    <span class="keyword">final</span> Stream&lt;Character&gt; flatMap = strings.stream()</span><br><span class="line">                                             .flatMap(Java8StreamTest::getCharacterByString);</span><br><span class="line">    flatMap.forEach(System.out::println);</span><br><span class="line">    <span class="comment">//----------------------------------------------</span></span><br><span class="line">    <span class="keyword">final</span> Stream&lt;Stream&lt;Character&gt;&gt; mapStream = strings.stream()</span><br><span class="line">                                                       .map(Java8StreamTest::getCharacterByString);</span><br><span class="line">    <span class="comment">//mapStream.forEach(System.out::println);</span></span><br><span class="line">    out.println(<span class="string">&quot;------------------------------------------------&quot;</span>);</span><br><span class="line">    mapStream.forEach(</span><br><span class="line">        stream-&gt; &#123;stream.forEach(character-&gt;&#123;System.out.println(character);&#125;);&#125;</span><br><span class="line">        );</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>公共方法（字符串转换为字符流）</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 功能描述:字符串转换为字符流</span></span><br><span class="line"><span class="comment">* <span class="doctag">@param</span> str</span></span><br><span class="line"><span class="comment">* <span class="doctag">@return</span> : java.util.stream.Stream&lt;java.lang.Character&gt;</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> Stream&lt;Character&gt; <span class="title">getCharacterByString</span><span class="params">(String str)</span> </span>&#123;</span><br><span class="line">    List&lt;Character&gt; characterList = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">    <span class="keyword">for</span> (Character character : str.toCharArray()) &#123;</span><br><span class="line">    	characterList.add(character);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> characterList.stream();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="终止操作符"><a href="#终止操作符" class="headerlink" title="终止操作符"></a>终止操作符</h3><table>
<thead>
<tr>
<th>流方法</th>
<th>含义</th>
<th>示例</th>
</tr>
</thead>
<tbody><tr>
<td>anyMatch</td>
<td>检查是否至少匹配一个元素，返回boolean。</td>
<td>List<String> strings = Arrays.asList(“abc”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);boolean b = strings.stream().anyMatch(s -&gt; s == “abc”);</String></td>
</tr>
<tr>
<td>allMatch</td>
<td>检查是否匹配所有元素，返回boolean。</td>
<td>List<String> strings = Arrays.asList(“abc”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);boolean b = strings.stream().allMatch(s -&gt; s == “abc”);</String></td>
</tr>
<tr>
<td>noneMatch</td>
<td>检查是否没有匹配所有元素，返回boolean。</td>
<td>List<String> strings = Arrays.asList(“abc”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);boolean b = strings.stream().noneMatch(s -&gt; s == “abc”);</String></td>
</tr>
<tr>
<td>findAny</td>
<td>将返回当前流中的任意元素。</td>
<td>List<String> strings = Arrays.asList(“cv”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);Optional<String> any = strings.stream().findAny();</String></String></td>
</tr>
<tr>
<td>findFirst</td>
<td>返回第一个元素</td>
<td>List<String> strings = Arrays.asList(“cv”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);Optional<String> first = strings.stream().findFirst();</String></String></td>
</tr>
<tr>
<td>forEach</td>
<td>遍历流</td>
<td>List<String> strings = Arrays.asList(“cv”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);strings.stream().forEach(s -&gt; out.println(s));</String></td>
</tr>
<tr>
<td>collect</td>
<td>收集器，将流转换为其他形式。</td>
<td>List<String> strings = Arrays.asList(“cv”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);Set<String> set = strings.stream().collect(Collectors.toSet());List<String> list = strings.stream().collect(Collectors.toList());Map&lt;String, String&gt; map = strings.stream().collect(Collectors.toMap(v -&gt;v.concat(“_name”), v1 -&gt; v1, (v1, v2) -&gt; v1));</String></String></String></td>
</tr>
<tr>
<td>reduce</td>
<td>可以将流中元素反复结合起来，得到一个值。</td>
<td>List<String> strings = Arrays.asList(“cv”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);Optional<String> reduce = strings.stream().reduce((acc,item) -&gt; {return acc+item;});if(reduce.isPresent())out.println(reduce.get());</String></String></td>
</tr>
<tr>
<td>count</td>
<td>返回流中元素总数。</td>
<td>List<String> strings = Arrays.asList(“cv”, “abd”, “aba”, “efg”, “abcd”,”jkl”, “jkl”);long count = strings.stream().count();</String></td>
</tr>
</tbody></table>
<blockquote>
<p>示例代码</p>
<p>1）anyMatch</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 判断集合中是否至少存在一个元素满足条件</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">anyMatch</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    <span class="keyword">boolean</span> b = strings.stream().anyMatch(s -&gt; s == <span class="string">&quot;abc&quot;</span>);</span><br><span class="line">    out.println(b);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>2）allMatch</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 判断集合中是否所有元素都满足条件</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">allMatch</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    <span class="keyword">boolean</span> b = strings.stream().allMatch(s -&gt; s == <span class="string">&quot;abc&quot;</span>);</span><br><span class="line">    out.println(b);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>3）noneMatch</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 判断集合中是否所有元素都不满足条件</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">noneMatch</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;abc&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    <span class="keyword">boolean</span> b = strings.stream().noneMatch(s -&gt; s == <span class="string">&quot;abc&quot;</span>);</span><br><span class="line">    out.println(b);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>4）findAny</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 返回当前流中任意元素</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">findAny</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;cv&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    Optional&lt;String&gt; any = strings.stream().findAny();</span><br><span class="line">    <span class="keyword">if</span>(any.isPresent()) out.println(any.get());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>5）findFirst</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 返回当前流中第一个元素</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">findFirst</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;cv&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    Optional&lt;String&gt; first = strings.stream().findFirst();</span><br><span class="line">    <span class="keyword">if</span>(first.isPresent()) out.println(first.get());</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>6）forEach java </p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 遍历流</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">foreach</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;cv&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    strings.stream().forEach(s -&gt; out.println(s));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>7）collect</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 流转换为其他形式</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">collect</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;cv&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    Set&lt;String&gt; set = strings.stream().collect(Collectors.toSet());</span><br><span class="line">    List&lt;String&gt; list = strings.stream().collect(Collectors.toList());</span><br><span class="line">    Map&lt;String, String&gt; map = strings.stream().collect(Collectors.toMap(v -&gt;v.concat(<span class="string">&quot;_name&quot;</span>), v1 -&gt; v1, (v1, v2) -&gt; v1));</span><br><span class="line">    out.println(set);</span><br><span class="line">    out.println(list);</span><br><span class="line">    out.println(map);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>8）reduce</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能描述 : 将流中元素反复结合起来，得到一个值</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">reduce</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;cv&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    <span class="comment">//reduce方法一</span></span><br><span class="line">    Optional&lt;String&gt; reduce1 = strings.stream().reduce((acc,item) -&gt; &#123;<span class="keyword">return</span> acc+item;&#125;);</span><br><span class="line">    <span class="comment">//reduce方法二</span></span><br><span class="line">    String reduce2 = strings.stream().reduce(<span class="string">&quot;itcast&quot;</span>, (acc, item) -&gt; &#123;</span><br><span class="line">    	<span class="keyword">return</span> acc + item;</span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="comment">//reduce方法三</span></span><br><span class="line">    ArrayList&lt;String&gt; reduce3 = strings.stream().reduce(</span><br><span class="line">        <span class="keyword">new</span> ArrayList&lt;String&gt;(),</span><br><span class="line">   		<span class="keyword">new</span> BiFunction&lt;ArrayList&lt;String&gt;, String, ArrayList&lt;String&gt;&gt;() &#123;</span><br><span class="line">    		<span class="meta">@Override</span></span><br><span class="line">    		<span class="function"><span class="keyword">public</span> ArrayList&lt;String&gt; <span class="title">apply</span><span class="params">(ArrayList&lt;String&gt; acc, String item)</span> </span>&#123;</span><br><span class="line">    			acc.add(item);</span><br><span class="line">    			<span class="keyword">return</span> acc;</span><br><span class="line">    		&#125;</span><br><span class="line">    	&#125;, </span><br><span class="line">        <span class="keyword">new</span> BinaryOperator&lt;ArrayList&lt;String&gt;&gt;() &#123;</span><br><span class="line">   			<span class="meta">@Override</span></span><br><span class="line">    		<span class="function"><span class="keyword">public</span> ArrayList&lt;String&gt; <span class="title">apply</span><span class="params">(ArrayList&lt;String&gt; acc, ArrayList&lt;String&gt; item)</span> </span>&#123;</span><br><span class="line">    		<span class="keyword">return</span> acc;</span><br><span class="line">    		&#125;</span><br><span class="line">    	&#125;</span><br><span class="line">    );</span><br><span class="line">    <span class="keyword">if</span>(reduce1.isPresent())out.println(reduce1.get());</span><br><span class="line">    out.println(reduce2);</span><br><span class="line">    out.println(reduce3);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>9）count</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* 功能描述 : 返回流中元素总数</span></span><br><span class="line"><span class="comment">* <span class="doctag">@return</span> : void</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">count</span><span class="params">()</span></span>&#123;</span><br><span class="line">    List&lt;String&gt; strings = Arrays.asList(<span class="string">&quot;cv&quot;</span>, <span class="string">&quot;abd&quot;</span>, <span class="string">&quot;aba&quot;</span>, <span class="string">&quot;efg&quot;</span>, <span class="string">&quot;abcd&quot;</span>,<span class="string">&quot;jkl&quot;</span>, <span class="string">&quot;jkl&quot;</span>);</span><br><span class="line">    <span class="keyword">long</span> count = strings.stream().count();</span><br><span class="line">    out.println(count);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</blockquote>
<p>注意：文章中因排序部分用到外部比较器，需要导入外部jar包</p>
<figure class="highlight xml"><table><tr><td class="code"><pre><span class="line"><span class="comment">&lt;!--apache集合操作工具包--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.commons<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>commons-collections4<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>4.4<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://code-ran.gitee.io">牛牛</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://code-ran.gitee.io/2022/11/23/java8Stream%E8%AF%A6%E8%A7%A3/">https://code-ran.gitee.io/2022/11/23/java8Stream%E8%AF%A6%E8%A7%A3/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://code-ran.gitee.io" target="_blank">牛牛&blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/java8/">java8</a></div><div class="post_share"><div class="social-share" data-image="" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/11/23/Mybatis%E4%B8%ADCDATA%E7%9A%84%E4%BD%BF%E7%94%A8/"><img class="prev-cover" src="" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Mybatis中 &lt;![CDATA[ ]]&gt; 的使用</div></div></a></div><div class="next-post pull-right"><a href="/2022/11/23/java8%E9%9B%86%E5%90%88%E4%B9%8B%E9%97%B4%E7%9A%84%E6%AF%94%E8%BE%83/"><img class="next-cover" src="" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">java8集合之间的比较</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2022/11/23/%E5%B7%A5%E4%BD%9C%E4%B8%AD%E5%B8%B8%E7%94%A8%E7%9A%84lambda%E6%80%BB%E7%BB%93/" title="工作中常用的lambda总结"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-23</div><div class="title">工作中常用的lambda总结</div></div></a></div><div><a href="/2022/11/23/java8%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BC%96%E7%A8%8B/" title="java8函数式编程"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-23</div><div class="title">java8函数式编程</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/ys.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">牛牛</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">52</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">26</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/code-ran"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">本blog内容仅用于个人学习使用!</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#JDK8-Stream%E8%AF%A6%E8%A7%A3"><span class="toc-number">1.</span> <span class="toc-text">JDK8 Stream详解</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A6%82%E5%BF%B5"><span class="toc-number">1.1.</span> <span class="toc-text">概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%89%B9%E7%82%B9"><span class="toc-number">1.2.</span> <span class="toc-text">特点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%81%E7%A8%8B"><span class="toc-number">1.3.</span> <span class="toc-text">流程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%93%8D%E4%BD%9C%E7%AC%A6"><span class="toc-number">1.4.</span> <span class="toc-text">操作符</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%AD%E9%97%B4%E6%93%8D%E4%BD%9C%E7%AC%A6"><span class="toc-number">1.4.1.</span> <span class="toc-text">中间操作符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%88%E6%AD%A2%E6%93%8D%E4%BD%9C%E7%AC%A6"><span class="toc-number">1.4.2.</span> <span class="toc-text">终止操作符</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/04/30/springboot%E6%B3%A8%E8%A7%A3%E7%9B%B8%E5%85%B3/" title="springboot注解相关">springboot注解相关</a><time datetime="2024-04-30T03:20:37.000Z" title="发表于 2024-04-30 11:20:37">2024-04-30</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2024/04/30/CommandLineRunner%E5%92%8CApplicationRunner%E7%94%A8%E6%B3%95%E4%B8%8E%E5%8C%BA%E5%88%AB/" title="CommandLineRunner和ApplicationRunner用法与区别">CommandLineRunner和ApplicationRunner用法与区别</a><time datetime="2024-04-30T02:42:21.000Z" title="发表于 2024-04-30 10:42:21">2024-04-30</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/12/08/%E5%A5%BD%E6%96%87%E6%94%B6%E8%97%8F/" title="好文收藏">好文收藏</a><time datetime="2023-12-08T08:40:13.000Z" title="发表于 2023-12-08 16:40:13">2023-12-08</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/12/08/springboot%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD/" title="springboot文件上传下载">springboot文件上传下载</a><time datetime="2023-12-08T03:30:54.000Z" title="发表于 2023-12-08 11:30:54">2023-12-08</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/12/05/linux%E4%BD%BF%E7%94%A8curl%E5%91%BD%E4%BB%A4%E5%8F%91%E9%80%81%E8%AF%B7%E6%B1%82/" title="linux使用curl命令发送请求">linux使用curl命令发送请求</a><time datetime="2023-12-05T05:56:19.000Z" title="发表于 2023-12-05 13:56:19">2023-12-05</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2024 By 牛牛</div><div class="footer_custom_text">Hi, Welcome to my blog!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">簡</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>